package com.cadre.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cadre.common.exception.RRException;
import com.cadre.common.utils.oldutil.PageUtils;
import com.cadre.common.utils.oldutil.Query;
import com.cadre.system.domain.officer.SearchTag;
import com.cadre.system.domain.officer.SysConfigEntity;
import com.cadre.system.domain.officer.config.SysConfigRedis;
import com.cadre.system.mapper.SysConfigMapper;
import com.cadre.system.service.SysConfigService;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service("sysConfigService")
/* loaded from: SysConfigServiceImpl.class */
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfigEntity> implements SysConfigService {
    @Autowired
    private SysConfigRedis sysConfigRedis;
    @Autowired
    private SysConfigMapper sysConfigMapper;

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public PageUtils queryPage(Map<String, Object> params) {
        String paramKey = (String) params.get("paramKey");
        return new PageUtils(this.baseMapper.selectPage(new Query(params).getPage(),
                new LambdaQueryWrapper<SysConfigEntity>().like(StringUtils.isNotBlank(paramKey), SysConfigEntity::getParamKey, paramKey)
                        .eq(SysConfigEntity::getStatus, 1)));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public boolean save(SysConfigEntity config) {
        this.baseMapper.insert(config);
        return true;
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    @Transactional(rollbackFor = {Exception.class})
    public void update(SysConfigEntity config) {
        updateById(config);
        this.sysConfigRedis.saveOrUpdate(config);
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    @Transactional(rollbackFor = {Exception.class})
    public void updateValueByKey(String key, String value) {
        this.baseMapper.updateValueByKey(key, value);
        this.sysConfigRedis.delete(key);
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    @Transactional(rollbackFor = {Exception.class})
    public void deleteBatch(Long[] ids) {
        removeBatchByIds(Arrays.asList(ids));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public String getValue(String key) {
        SysConfigEntity config = this.sysConfigRedis.get(key);
        if (config == null) {
            config = this.baseMapper.queryByKey(key);
            this.sysConfigRedis.saveOrUpdate(config);
        }
        if (config == null) {
            return null;
        }
        return config.getParamValue();
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public <T> T getConfigObject(String key, Class<T> clazz) {
        String value = getValue(key);
        if (StringUtils.isNotBlank(value)) {
            return (T) new Gson().fromJson(value, clazz);
        }
        try {
            return clazz.newInstance();
        } catch (Exception e) {
            throw new RRException("获取参数失败");
        }
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SysConfigEntity> queryWarningConfigs() {
        return this.baseMapper.selectList(new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "预警%_")
                .eq(SysConfigEntity::getStatus, 0).orderByAsc(SysConfigEntity::getId));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SysConfigEntity> queryRangeConfigs() {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "预警信息_统计范围_")
                        .eq(SysConfigEntity::getStatus, 0).orderByAsc(SysConfigEntity::getId));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public SysConfigEntity queryCurrentYearWarningConfigs() {
        return (SysConfigEntity) this.baseMapper.selectOne(

                new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "预警设置_任现职满X年")
                        .eq(SysConfigEntity::getParamKey, "CURRENT_YEAR").orderByAsc(SysConfigEntity::getId)
                        .eq(SysConfigEntity::getStatus,0));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SysConfigEntity> querySearchConfigs() {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "智搜_")
                        .eq(SysConfigEntity::getStatus, 0).orderByAsc(SysConfigEntity::getId));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SysConfigEntity> querySearchTypeConfigs() {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "智搜_类别")
                        .eq(SysConfigEntity::getStatus, 0).orderByAsc(SysConfigEntity::getId));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SysConfigEntity> querySearchDetailConfigs(String type) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "智搜_")
                        .eq(SysConfigEntity::getStatus, 0).orderByAsc(SysConfigEntity::getId));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SysConfigEntity> queryModelInfoConfigs(String type) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<SysConfigEntity>().like(SysConfigEntity::getRemark, "报表模版_")
                        .eq(SysConfigEntity::getStatus, 0).orderByAsc(SysConfigEntity::getId));
    }

    @Override // com.tdqy.cadre.modular.system.service.SysConfigService
    public List<SearchTag> querySearchDetailConfigsForDisplay(String type) {
        return this.sysConfigMapper.querySearchDetailConfigsForDisplay(type);
    }
}
